package cn.itsource.hrm.service.impl;

import cn.itsource.hrm.domain.Course;
import cn.itsource.hrm.domain.CourseDetail;
import cn.itsource.hrm.domain.CourseMarket;
import cn.itsource.hrm.domain.dto.CourseDTO;
import cn.itsource.hrm.mapper.CourseDetailMapper;
import cn.itsource.hrm.mapper.CourseMapper;
import cn.itsource.hrm.mapper.CourseMarketMapper;
import cn.itsource.hrm.service.ICourseService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2020-12-17
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements ICourseService {

    @Autowired
    private CourseMarketMapper courseMarketMapper;

    @Autowired
    private CourseDetailMapper courseDetailMapper;


    @Override
    public void save(CourseDTO courseDto) {
        Course course = courseDto.getCourse();
        CourseDetail courseDetail = courseDto.getCourseDetail();
        CourseMarket courseMarket = courseDto.getCourseMarket();
        //1. 参数的验证 非空，合法性;
        //2. 保存课程基本数据；
        //课程的状态 默认为 先是位上架;
        course.setStatus(Course.OFF_LINE);
        course.setTenantId(1L);
        course.setTenantName("源码时代");
        course.setUserName("源码时代");
        course.setUserId(1L);
        course.setSaleCount(0);
        course.setViewCount(0);
        course.setCommentCount(0);
        baseMapper.insert(course);
        //3. 保存课程营销数据
        courseMarket.setId(course.getId());
        courseMarketMapper.insert(courseMarket);
        //4. 保存课程详情
        courseDetail.setId(course.getId());
        courseDetailMapper.insert(courseDetail);
    }
}
